package com.darren.euc.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonFormat;

@Entity
@Table(name = "euc_user_role")
public class Manager implements Serializable {

	private static final long serialVersionUID = 2861478466077717714L;

	@Id
	@Column(name = "id")
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	
	//@Column(name = "user_id")
	@Transient
	private String userId;	
	
	//@Column(name = "role_id")
	@Transient
	private String roleId;

	@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
	@Column(name = "create_time")
	private Date createTime;
	
	@Transient
	private String roleName;
	
	@Transient
	private String name;
	
	@Transient
	private String mobile;
	
	@Transient
	private String functionNames;
	
	@OneToOne(cascade=CascadeType.REFRESH)
	@JoinColumn(name="user_id")
    private User user;
	
	@OneToOne(cascade=CascadeType.REFRESH)
	@JoinColumn(name="role_id")
    private Role role;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getUserId() {
		if(user != null){
			this.userId = user.getId().toString();
		}
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getRoleId() {
		if(role != null){
			this.roleId = role.getId().toString();
		}
		return roleId;
	}

	public void setRoleId(String roleId) {
		this.roleId = roleId;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Role getRole() {
		return role;
	}
	
	public void setRole(Role role) {
		this.role = role;
	}
	
	public String getRoleName() {
		if(role != null){
			this.roleName = role.getRoleName();
		}
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public String getName() {
		if(user != null){
			this.name = user.getName();
		}
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getMobile() {
		if(user != null){
			this.mobile = user.getMobile();
		}
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getFunctionNames() {
		if(role != null){
			this.functionNames = role.getFunctionNames();
		}
		return functionNames;
	}

	public void setFunctionNames(String functionNames) {
		this.functionNames = functionNames;
	}
	
}
